package com.lee.strategy.service.impl;

import com.lee.strategy.enumeration.AuditEnum;
import com.lee.strategy.service.AuditService;
import com.lee.strategy.service.StrategyService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author zfl_a
 * @date 2020/8/10
 * @project springboot_design_pattern
 */
@Service
public class StrategyServiceImpl implements StrategyService {

    //自动装配AuditService的所有实现类，以全类名首字母小写作为key
    @Autowired
    private Map<String, AuditService> auditMap ;

    @Override
    public boolean audit(String name, String msg, String type) {

        if(StringUtils.isBlank(type)) {
            return false ;
        }

        //根据不同类型审核
        String auditType = AuditEnum.getImpl(type);
        if(StringUtils.isNotBlank(auditType)) {
            AuditService auditService = auditMap.get(auditType);
            auditService.operation(name,msg);
        }

        return true;
    }
}
